﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace TinySocket
{
    public class Connection
    {
        Socket socket;

        Thread receiveThread;

        Connection() { }

        public void Close()
        {
            SocketExtensions.CloseSocket(socket);
        }

        static void ReceiveThreadFunction(object state)
        {
            Connection connection = state as Connection;
            try
            {
                while (true)
                {



                }


                
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }

        }

        static Connection Create(Socket socket)
        {
            Connection connection = new Connection();
            connection.socket = socket;
            connection.receiveThread = new Thread(ReceiveThreadFunction);
            connection.receiveThread.Start(connection);
            return connection;
        }

        public static Connection CreateForAccept(Socket socket)
        {
            return Create(socket);
        }
    }
}
